<template>
	<view class="content">
		<my-public :currentIndex="currentIndex" :navList="navList" :navIndex="navIndex" @getList="getList"></my-public>
		<!-- 内容 -->
		<list :list='news' :status="status" :contentText="contentText" stateType="0"></list>
	</view>
</template>

<script>
	import list from '@/components/artlist/artlist.vue';
	import myPublic from './components/myPublic.vue';
	import util from '@/common/util.js';
	import uniLoadMore from '@/components/uni-load-more/uni-load-more.vue';
	export default {
		components: {
			list,
			myPublic,
			uniLoadMore
		},
		data() {
			return {
				currentIndex: 2,
				navList: [], //类型列表
				navIndex: 0,
				buttomIndex: 1,
				news: [], //新闻列表
				reload: true,
				page: 1,
				status: 'more',
				contentText: {
					contentdown: '上拉加载更多',
					contentrefresh: '加载中',
					contentnomore: '没有更多',
					contentnot: "没数据"
				}
			}
		},
		onPullDownRefresh() {
			this.reload = true;
			this.page = 1;
			this.getList();
			setTimeout(function() {
				uni.stopPullDownRefresh();
			}, 1000);
		},
		onReachBottom() {
			this.status = 'loading';
			this.page = this.page + 1;
			var _this = this;
			setTimeout(function() {
				_this.getList();
			}, 500);
		},
		onShow() {
			this.reload = true;
			this.page = 1;
			this.getList();
		},
		onLoad() {
			this.getType();
		},
		methods: {
			/* 获取文章列表 */
			getList(value) {
				if (value) {
					this.navIndex = value.index;
					this.page = value.page;
					this.reload = value.reload;
				}
				var data = {
					is_check: 2, //2通过 仅查看通过审核的文章
					page: this.page,
					pagesize: 7
				}
				if (this.navIndex) {
					data.article_type_id = this.navList[this.navIndex].article_type_id;
				}
				this.$zapi.apiPost('user/article.Lists/articleList', data).then(res => {
					if (res.data.code == 200) {
						var list = res.data.data.data;
						for (var i = 0; i < list.length; i++) {
							list[i].time = util.getBriefTime(list[i].creat_time);
							if (list[i].subhead_creat_time) {
								list[i].ftime = util.getBriefTime(list[i].subhead_creat_time);
							}
						}
						this.news = this.reload ? list : this.news.concat(list);
						this.reload = false;
						this.status = 'more';
					} else {
						if (this.reload) {
							this.news = [];
						} else {
							this.status = 'noMore';
						}
					}
				})
			},
			/* 获取文章分类列表 */
			getType() {
				this.$zapi.apiPost('user/article.Lists/listType').then(res => {
					if (res.data.code == 200) {
						var da = res.data.data;
						if (da) {
							da.unshift({
								article_name: "全部",
								article_type_id: null
							});
						}
						for (let i = 0; i < da.length; i++) {
							da[i].name = da[i].article_name;
						}
						this.navList = da;
					} else {
						this.navList.unshift({
							article_name: "全部",
							article_type_id: null
						});
					}
				})
			}
		}
	}
</script>
